<?php

class GlobalBrandController extends AppController {

    var $name = 'GlobalBrand';
    var $uses = array('Brand', 'Brandsetting');

    function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow = array('*');
    }

    function index($id=null) {
        $this->layout = false;
        if (!empty($this->data)) {
            if ($this->Brandsetting->save($this->data)) {
                $this->Session->setFlash(__("Global " . $id . " settings has been updated successfully.", true));
                //$this->redirect(array('action' => 'index',$this->data['brand_type']));				
            } else {
                $this->Session->setFlash(__("Global " . $id . " settings could not be saved. Please, try again.", true));
            }
        }
        $this->data['brand_type'] = $id;
        $this->data['brand_settings'] = $this->Brandsetting->find('first', array('conditions' => array('brand_type' => $id)));
        $this->data['global_brand'] = $this->Brand->find('all', array('conditions' => array('Brand.brand_type' => $id), 'order' => 'Brand.brand_description ASC'));
    }

    function success() {
        $this->layout = false;
    }

    function add() {
        $this->layout = false;
        if (!empty($this->data)) {
            $this->Brand->create();
            if ($this->Brand->save($this->data)) {
                $this->Session->setFlash(__("Global " . $this->data['brand_type'] . " has been saved successfully.", true));
                $this->redirect(array('action' => 'index', $this->data['brand_type']));
            } else {
                $this->Session->setFlash(__('The Category could not be saved. Please, try again.', true));
            }
        }
    }

    function edit() {
        $this->layout = false;
        if ($this->Brand->save($this->data)) {
            $return_arr['message'] = "Yes";
        } else {
            $return_arr['message'] = "No";
        }
        echo json_encode($return_arr);
        $this->autoRender = false;
    }

    function delete($id = null, $id2=null) {
        $this->layout = false;
        if (!empty($this->data)) {
            if ($this->Brand->delete($id)) {
                $this->Session->setFlash(__("Global $id2 has been deleted successfully.", true));
                $this->redirect(array('action' => 'index', $id2));
            } else {
                $this->Session->setFlash(__("The global $id2 could not be saved. Please, try again.", true));
            }
        }
        if ($id && empty($this->data)) {
            $this->data = $this->Brand->read(null, $id);
        }
    }

}

?>